package com.film.controller;

import com.film.pojo.User;
import com.film.service.UserService;
import com.film.vo.PageResult;
import com.film.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author Sora
 * @date 2021/1/20 19:17
 */
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    //验证码
    private StringBuilder stringBuilder = new StringBuilder(4);


    @PostMapping("/user/userLogin")
    public SysResult userLogin(@RequestBody  User user){
        User user1=userService.userLogin(user);
        if(user1!=null){
            return SysResult.success(user1);
        }
        return SysResult.fail();
    }


    @PutMapping("/user/updateUser")
       public SysResult updateUser(@RequestBody User user){
        boolean bl=userService.updateUser(user);
        if(bl){
            return SysResult.success();
        }
        return SysResult.fail();
    }

    @PostMapping("/user/updateAvatar")
    public SysResult updateAvatar(@RequestParam("file") MultipartFile file,@RequestParam("id") Integer id) {
          Boolean bl= userService.updateAvatar(file,id);
          if(bl){
              return SysResult.success();
          }
          return SysResult.fail();
    }


    @GetMapping("/user/getUserInfo/{id}")
    public SysResult getUserInfo(@PathVariable Integer id){
      User user=userService.getUserInfo(id);
      if(user==null){
          return SysResult.fail();
      }
      return SysResult.success(user);
    }
    @PostMapping("/user/saveUserInfo")
    public SysResult saveUserInfo(@RequestBody User user){
       boolean bl=userService.saveUserInfo(user);
       if(bl){
           return SysResult.success();
       }
       return SysResult.fail();
    }
}
